@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script type="text/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script>
    <link href="{{url('js/lib/jquery-ui-timepicker-addon.css')}}" type="text/css" />
    <script src="{{url('js/lib/jquery-ui-timepicker-addon.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery.ui.datepicker-zh-CN.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery-ui-timepicker-zh-CN.js')}}" type="text/javascript"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
    @include('UEditor::head')
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">计划管理</a>
            <em>></em>
            <a href="#">添加计划</a>
        </div>
        <!-- cur-position end -->

        <div class="gg-step">
            <form  id="advform">
                <input type="hidden" name="id" id="page_id" value="@if($page){{$page->id}}@endif"/>

                <div class="gg-list">
                    <label class="tit">模块名称：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入模块名称" name="title" id="title" value="@if($page){{$page->title}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">可输入2-40个字符（一个汉字等于2个字符）</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">模块链接：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入模块链接（跳转链接)" name="link" id="link" value="@if($page){{$page->link}}@endif" /><cite id="title_re" class="required">*</cite>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">模块标签：</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入模块标签" name="tag" id="tag" value="@if($page){{$page->tag}}@endif" /><cite id="title_re" class="required">*</cite>
                    </div>
                </div>

                <div class="gg-list" data-id="ggwz">
                    <label class="tit">模块内容：</label>
                    <div class="cont">
                        <textarea placeholder="请输入模块内容" name="description" id="aa"></textarea>
                    </div>
                </div>

            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn_send">提交</a>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            <!-- 实例化编辑器 -->
            var ue = UE.getEditor('aa',{
                autoHeightEnabled: true,
                initialFrameHeight:400,
                initialFrameWidth:600,
                toolbars: [
                    ['fullscreen', 'undo','redo','|','fontsize','horizontal','|','simpleupload','insertvideo','removeformat'],
                    ['bold', 'italic', 'underline', 'forecolor', 'backcolor','|','indent','|','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','|','insertunorderedlist', 'insertorderedlist','|', 'imagenone','imageleft','imageright','imagecenter','|','link']
                ]
            });

            @if($page)
            ue.ready(function() {
                ue.setContent('<?php echo $page->content ?>');
            });
            @endif


            $('#btn_send').click(function () {
                var title = $('#title').val();
                var link = $('#link').val();
                var tag = $('#tag').val();
                var id = $('#page_id').val();
                var content = '';

                ue.ready(function () {
                    content = ue.getContent();
                });

                $.ajax({
                    url: "{{route('Api.Admin.Page.setPage')}}",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id: id,
                        title: title,
                        link: link.trim(),
                        tag: tag,
                        content: content
                    },
                    success: function (obj) {
                        if (obj.level == 'success') {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose: function () {
                                        window.location.href = "{{route('Admin.Home.pageManager')}}";
                                    }
                                }
                            });
                        } else {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }
                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>
@endsection